package handler

import (
	"github.com/go-playground/validator/v10"
	"sgo/common/response"
	"sgo/scontext"
)

//type ErrorHandler struct {}

type ErrorHandler interface {
	handleError(sc *scontext.SgoContext, err error) response.Response
}

// 统一异常处理

func HandleError(sc *scontext.SgoContext, err error) response.Response {

	switch err.(type) {
	case validator.ValidationErrors:
		return ValidationErrorHandler{}.handleError(sc, err)
	default:
		return response.FailWithMessage(err.Error())
	}
}
